package com.ren.controller;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ren.model.Person;

import javafx.scene.chart.PieChart.Data;

@Controller
@RequestMapping("/mvc")
public class mvcController {
	
	@RequestMapping("/hello")
	public String hello(){
		return "hello";
	}
	
	@RequestMapping("/person")
	public String toPerson(String name,double age){
		System.out.println(name+ " " + age);
		return "hello";
	}
	
	@RequestMapping("/person1")
	public String toPerson(Person p){
		System.out.println(p.getName()+ " " + p.getAge());
		return "hello";
	}
	
	@RequestMapping("/date")
	public String date(Date date){
		System.out.println(date);
		return "hello";
	}
	
	@InitBinder
	public void initBinder(ServletRequestDataBinder binder){
		binder.registerCustomEditor(Data.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
	}
	
	@RequestMapping("/show")
	public String showPerson(Map<String,Object> map){
		Person p = new Person();
		map.put("p",p);
		p.setAge(20);
		p.setName("klren");
		return "show";
	}
	
	@RequestMapping("/getPerson")
	public void getPerson(String name,PrintWriter pw){
		pw.write("hello," + name);
	}
	@RequestMapping("/name")
	public String sayHello(){
		return "name";
	}
	
}
